<?php

	require_once "../../konfigurasi.php";
	
	koneksi_buka();
	
	if(isset($_GET['id'])){
		$id = $_GET['id'];
	}
	
	if(isset($_POST['id'])){
		$id = $_POST['id'];
	}
	
	if(isset($_POST['materi'])){
		$materi = $_GET['materi'];
	}
	
	if(isset($_POST['siswa'])){
		$siswa = $_POST['siswa'];
	}
	
	if(isset($_POST['guru'])){
		$guru = $_POST['guru'];
	}
	
	if(isset($_POST['latihan'])){
		$latihan = $_POST['latihan'];
	}
	if(isset($_POST['tugas'])){
		$tugas = $_POST['tugas'];
	}
	if(isset($_POST['uts'])){
		$uts = $_POST['uts'];
	}
	if(isset($_POST['uas'])){
		$uas = $_POST['uas'];
	}
	if(isset($_POST['akhir'])){
		$akhir = $_POST['akhir'];
	}
	if(isset($_POST['harian'])){
		$harian = $_POST['harian'];
	}	
		
	$tgl_daftar = date("Y-m-d");
	$wkt = date("H:i:s");
	
	if($operation=="get_text"){
		$q_siswa = mysql_query("select * from siswa where nis='$nis'");
		if($dt_siswa = mysql_fetch_array($q_siswa)) {
			echo $dt_siswa['nama']." (".$dt_siswa['kelas'].")";
		}
	}else if($operation == "add") {
	
		$q = "INSERT INTO nilai
			(materi, siswa, guru, latihan, tugas, uts, uas, akhir, harian) 
			VALUES('$materi', '$siswa', '$guru', '$latihan', '$tugas', '$uts', '$uas', '$akhir', '$harian')";
		$result = mysql_query($q);
		if($result){
			header("Location:../../index.php");
		}else{
			echo 'failed query :'.$q ;
		}
		
		
	}else if($operation == "edit") {
		$result = mysql_query("UPDATE nilai SET 
			materi = '$materi', 
			siswa = '$siswa', 
			guru = '$guru', 
			latihan = '$latihan', 
			tugas = '$tugas, 
			uts = '$uts',
			uas = '$uas',
			akhir = '$akhir', 
			harian = '$harian'
			WHERE id=".$id);
			
		if($result){
			echo 'success';
		}else{
			echo 'failed';
		}
		
		
	}else if($operation == "remove") {
		
		$result = mysql_query("DELETE FROM nilai WHERE id=".$id);
	
		if($result){
			echo 'success';
		}else{
			echo 'failed';
		}
		
	}
?>
